var express = require('express');
var getRouter = express.Router();
var postRouter = express.Router();
var axios = require('axios')
var rootApi = "http://112.74.105.17:20003/question-bank"
/* GET users listing. */
getRouter.get('/checkAnswer', function (req, res, next) {
    console.log(req.query.data)
    var thisApi = '/wx/stem/answer'
    // axios.get(rootApi + thisApi + questionId)
    //     .then(function (response) {
    //         res.send(response.data);
    //     })
    //     .catch(function (error) {
    //         console.log(error);
    //     });

});

postRouter.post('/checkAnswer', function (req, res, next) {
    var thisApi = '/wx/stem/answer'
    var answers=[]

    var handleAnswer=[]
    handleAnswer=req.body.answers
    handleAnswer.forEach(element => {
        answers.push(element.substring(1,(element.length-1)))
    });

    var stemId=JSON.stringify(req.body.stemId)
    console.log(JSON.stringify(req.body))
    console.log(answers+" "+stemId)

    axios.post(rootApi + thisApi, {
        answers:answers,
        stemId:stemId
    })
        .then(function (response) {
            res.send(response.data.data)
        })
        .catch(function (error) {
            console.log(error);
        });
});

exports.get = getRouter;
exports.post = postRouter;
// module.exports = router;
